﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class HotelPopular
    {
        #region
        public eHotelPopular Data;
        public HotelPopular()
        {
            Data = new eHotelPopular();
        }
        ~HotelPopular()
        {
        }
        public virtual void Dispose()
        {
        }
        public int DeleteById(int ID)
        {
            int nResult = 0;
            cHotelPopular objDAL = new cHotelPopular();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        public void LoadById(int ID)
        {
            cHotelPopular objDAL = new cHotelPopular();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }
        public DataTable GetAll()
        {
            DataTable tbResult = new DataTable();
            cHotelPopular objDAL = new cHotelPopular();
            tbResult = objDAL.GetAll();
            return tbResult;
        }
        public int Insert()
        {
            int nResult = 0;
            cHotelPopular objInfor = new cHotelPopular();
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.HotelPopularID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cHotelPopular objInfor = new cHotelPopular();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        private void MappingData(cHotelPopular objInfor)
        {
            try{objInfor.Description1 = Data.Description1;}
            catch{objInfor.Description1 = "";}
            try { objInfor.Description2 = Data.Description2; }
            catch { objInfor.Description2 = ""; }
            try { objInfor.Description3 = Data.Description3; }
            catch { objInfor.Description3 = ""; }
        }
        private void ConvertData(cHotelPopular objInfor)
        {
            Data.Description1 = objInfor.Description1;
            Data.Description2 = objInfor.Description2;
            Data.Description3 = objInfor.Description3;
        }
        //public int UpdatePriority(int TourID, int Priority)
        //{
        //    int nResult = 0;
        //    cHotelPopular objDAL = new cHotelPopular();
        //    try
        //    {
        //        objDAL.LoadByPrimaryKey(TourID);
        //        objDAL.Priority = Priority;

        //        objDAL.Save();
        //        nResult = objDAL.HotelPopularID;
        //    }
        //    catch
        //    {
        //        nResult = 0;
        //    }
        //    return nResult;
        //}
        #endregion
    }
}
